package greg1992.lekcja5.tablice;


import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JEditorPane;

public class SixpackGUI extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JEditorPane[] sloty;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixpackGUI frame = new SixpackGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SixpackGUI() {
		final Sixpack sixpack = new Sixpack();
		
		
		setTitle("Skrzynka");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 447, 230);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		sloty = new JEditorPane[6];
		
		sloty[0] = new JEditorPane();
		sloty[0].setEnabled(false);
		sloty[0].setEditable(false);
		sloty[0].setBackground(Color.GREEN);
		sloty[0].setBounds(58, 25, 89, 50);
		contentPane.add(sloty[0]);
		
		sloty[1] = new JEditorPane();
		sloty[1].setEnabled(false);
		sloty[1].setEditable(false);
		sloty[1].setBackground(Color.GREEN);
		sloty[1].setBounds(178, 25, 89, 50);
		contentPane.add(sloty[1]);
		
		sloty[2] = new JEditorPane();
		sloty[2].setEnabled(false);
		sloty[2].setEditable(false);
		sloty[2].setBackground(Color.GREEN);
		sloty[2].setBounds(303, 25, 89, 50);
		contentPane.add(sloty[2]);
		
		sloty[3] = new JEditorPane();
		sloty[3].setEnabled(false);
		sloty[3].setEditable(false);
		sloty[3].setBackground(Color.GREEN);
		sloty[3].setBounds(58, 86, 89, 50);
		contentPane.add(sloty[3]);
		
		sloty[4] = new JEditorPane();
		sloty[4].setEnabled(false);
		sloty[4].setEditable(false);
		sloty[4].setBackground(Color.GREEN);
		sloty[4].setBounds(178, 86, 89, 50);
		contentPane.add(sloty[4]);
		
		sloty[5] = new JEditorPane();
		sloty[5].setEnabled(false);
		sloty[5].setEditable(false);
		sloty[5].setBackground(Color.GREEN);
		sloty[5].setBounds(303, 86, 89, 50);
		contentPane.add(sloty[5]);
		
		final JButton btnWezPrzedmiot = new JButton("Wez przedmiot");
		btnWezPrzedmiot.setBounds(159, 161, 131, 23);
		contentPane.add(btnWezPrzedmiot);
		
		btnWezPrzedmiot.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				sixpack.wezPiwo();
				int numerSlotu = 0;
				for(Piwo[] value : sixpack.getZawartosc()){
					for(Piwo value2 : value){
						if(value2 == null){
							sloty[numerSlotu].setBackground(Color.RED);
						}
						numerSlotu++;
					}
				}
				if(sixpack.stan() == 0){
					btnWezPrzedmiot.setEnabled(false);
				}
			}
		});
		
		
		
	}
}
